package com.zxsj.fdk.study.dao;


import com.zxsj.fdk.study.common.page.PageContentContainer;
import com.zxsj.fdk.study.common.utils.SQLUtils;
import com.zxsj.fdk.study.dao.base.BaseDao;
import com.zxsj.fdk.study.service.supplier.param.QuerySkuParam;
import com.zxsj.fdk.study.service.supplier.vo.SupplierSkuVO;
import org.jooq.SelectConditionStep;
import org.springframework.stereotype.Repository;


import static com.zxsj.fdk.study.db.tables.SupplierSku.SUPPLIER_SKU;
import static com.zxsj.fdk.study.db.tables.SupplierSpu.SUPPLIER_SPU;


@Repository
public class SupplierSkuDao extends BaseDao {


    public PageContentContainer<SupplierSkuVO> querySupplierSku(QuerySkuParam param) {
        SelectConditionStep<?> query = db.select(SUPPLIER_SKU.ID,
                SUPPLIER_SKU.SPU_ID,
                SUPPLIER_SKU.SKU_NAME,
                SUPPLIER_SPU.SPU_NAME,
                SUPPLIER_SKU.IMG_URL,
                SUPPLIER_SKU.COST_PRICE)
                .from(SUPPLIER_SKU)
                .leftJoin(SUPPLIER_SPU)
                .on(SUPPLIER_SKU.SPU_ID.eq(SUPPLIER_SPU.ID))
                .where(SUPPLIER_SKU.MERCHANT_ID.eq(param.getMerchantId())
                        .and(SUPPLIER_SKU.SKU_NAME.like(SQLUtils.surroundingLike(param.getSkuName()))));
        return getPageResult(query, param, SupplierSkuVO.class);
    }
}
